package com.example.classwork;

import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.icu.text.CaseMap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Calculation extends AppCompatActivity {
String TAG="rateCale";
float rate=0f;
float result=0f;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_calculation);

        Intent intent =getIntent();
        String title=intent.getStringExtra("title");
        String Rate=intent.getStringExtra("rate");
        rate=Float.parseFloat(Rate);
        //rate=Float.parseFloat(getIntent().getStringExtra("rate"));

        Log.i(TAG,"onCreate:title="+title);
        Log.i(TAG,"onCreate:rate="+rate);
        ((TextView)findViewById(R.id.title2)).setText(title);

       // setResult(6,intent);
         //finish();
    }
    public void myClick(View btn) {
        EditText rmb = findViewById(R.id.rmb_inp);
        String str = rmb.getText().toString();


        if (str.length() == 0) {
            Toast.makeText(this, "请输入金额！", Toast.LENGTH_SHORT).show();
            return;
        } else {
            float i = Float.parseFloat(str);
            result = i * rate;
        }

        ((TextView) findViewById(R.id.result)).setText("结果为：" + result);
    }
}